﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class UControl_UCleft : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            rptdatabind();
        }

    }

    private void rptdatabind()
    {
        string sql = null;
        if (Bt == "热门新闻")
        {
            sql = @"select top 6 nid as id,list=substring(nsubject,0,18) + '...'
                                    from news inner join newstype on news.ntypeid = newstype.tid
                                    order by nhot desc";
           
        }
        else if (Bt == "最新评论")
        {
            sql = @"select top 6 cid as id,list=substring(ccontent,0,18)
                                    from comment
                                    order by cid desc";
        }
        YqhData obj = new YqhData();
        rptnewslist.DataSource = obj.FillDataSet(sql);
        rptnewslist.DataBind();
    }

    private string _Bt;
    public string Bt
    {
        get { return _Bt; }
        set { _Bt = value; }
    }


    protected void rptnewslist_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (Bt == "热门新闻")
        {
            switch (e.CommandName.ToLower())
            {
                case "check":
                    string sql = string.Format(@"update news set nhot=nhot+1
where nid={0}", e.CommandArgument);
                    YqhData obj = new YqhData();
                    obj.ExecuteSql(sql);
                    string url = string.Format("shownews.aspx?op=news&id={0}", e.CommandArgument);
                    Response.Redirect(url);
                    break;
            }
        }
        else if (Bt == "最新评论")
        {
            switch (e.CommandName.ToLower())
            {
                case "check":
                    YqhData obj = new YqhData();
                    string sql = string.Format("select cnewsid from comment where cid={0}",e.CommandArgument);
                    DataSet ds = obj.FillDataSet(sql);
                    int id = Convert.ToInt32(ds.Tables[0].Rows[0]["cnewsid"].ToString());
                    string url = string.Format("shownews.aspx?op=news&id={0}",id);
                    Response.Redirect(url);
                    break;
            }
        }
    }
}
